<template>
  <el-popover placement="bottom" width="auto" trigger="click">
    <template #reference>
      <p class="filter-btn flex-center flex-align-items-center pointer">
        <i class="iconfont icon-guolvqi"></i>
      </p>
    </template>
    <div>
      <el-cascader-panel :options="options" :props="propsInfo" />
      <div class="confirm-btn flex">
        <p class="pointer font-12" @click="reset">重置</p>
        <p class="pointer font-12" @click="confirm">确定</p>
      </div>
    </div>
  </el-popover>
</template>

<script setup>
import { defineProps, defineEmits, ref } from 'vue';
const props = defineProps(['check']);
const emit = defineEmits(['change']);

const propsInfo = {
  multiple: true,
  expandTrigger: 'hover'
};

const options = ref([
  {
    label: '数码电器',
    value: 1,
    children: [
      {
        label: '家用电器',
        value: 101
      },
      {
        label: '智能家居',
        value: 102
      }
    ]
  },
  {
    label: '办公设备',
    value: 2,
    children: [
      {
        label: '办公用品',
        value: 201
      },
      {
        label: '摄影器材',
        value: 201
      }
    ]
  },
  {
    label: '玩具',
    value: 201
  }
]);
const form = ref([...props.check]);

const reset = () => {
  emit('change', {});
}
const confirm = () => {
  emit('change', form.value);
}
</script>

<style lang="less" scoped>
.filter-btn {
  width: 48px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #f2f2f2;
  margin-left: 16px;

  &:hover {
    background: #f8f8f8;
  }

  i {
    color: #a1a1a1;
  }
}

.confirm-btn {
  padding: 10px 10px 10px 27px;

  p {
    width: 60px;
    height: 28px;
    border-radius: 3px;
    text-align: center;

    &:first-child {
      border: 1px solid #dcdfe6;
      color: #606266;
      line-height: 26px;
      margin-right: 10px;

      &:hover {
        color: @main-color;
        border-color: #ffcbd6;
        background-color: #ffeef1;
      }
    }

    &:last-child {
      background: @main-color;
      color: #fff;
      line-height: 28px;
    }
  }
}

::v-deep {
  .el-popper {
    width: auto !important;
  }
}
</style>